<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>FIRST</title>
		<style type="text/css">
			*{
				padding: 0;
				margin: 0;
			}
			.container{
				width: 100vw;
				height: 100vh;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		canvas{
			width: 400px;
			height: 400px;
			border: 10px solid #333333;
		}	
		
		</style>
	</head>
	<body>
		<div class="container">
		<canvas id="canvas" width="500" height="500"></canvas>
		</div>
	</body>
	<script>
		window.onload = function() {
			
			let oCanvas = document.getElementById('canvas');
		
			console.dir(oCanvas);
			
			let oPen=oCanvas.getContext("2d");
			
			console.dir(oPen);
			
			let data =[{
				name:'第一季度',
				value:100,
				color:'red'
			},{
				name:'第二季度',
				value:80,
				color:'green'
			},{
				name:'第三季度',
				value:90,
				color:'blue'
			},{
				name:'第四季度',
				value:305,
				color:'yellow'
			},]
			
			createSector(oPen,100,100,50,data);
			/**
			 * 
			 * @param {Object} open 笔的对象
			 * @param {Object} x 圆心坐标
			 * @param {Object} y 圆心坐标
			 * @param {Object} r 半径
			 * @param {Object} data 数据源
			 */
			function createSector(open,x,y,r,data){
				let sum=0;
				for(var i=0;i<data.length;i++){
					sum += data[i].value;
				}
				for(var i =0;i<data.length;i++){
					data[i].percentage = ((data[i].value*1.0)/sum)*360;
				}
				
				let startAngle = 0;
				for (var i=0;i<data.length;i++){
					oPen.beginPath()
					oPen.moveTo(x,y); 	
					oPen.arc(x,y,r,startAngle,startAngle+(Math.PI/180)*data[i].percentage,false);
					startAngle+=(Math.PI/180)*data[i].percentage;
					oPen.fillStyle=data[i].color;
					oPen.fill();
				}
			}
			
		}
	</script>
</html>
=======
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>FIRST</title>
		<style type="text/css">
			*{
				padding: 0;
				margin: 0;
			}
			.container{
				width: 100vw;
				height: 100vh;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		canvas{
			width: 400px;
			height: 400px;
			border: 10px solid #333333;
		}	
		
		</style>
	</head>
	<body>
		<div class="container">
		<canvas id="canvas" width="500" height="500"></canvas>
		</div>
	</body>
	<script>
		window.onload = function() {
			
			let oCanvas = document.getElementById('canvas');
		
			console.dir(oCanvas);
			
			let oPen=oCanvas.getContext("2d");
			
			console.dir(oPen);
			
			let data =[{
				name:'第一季度',
				value:100,
				color:'red'
			},{
				name:'第二季度',
				value:80,
				color:'green'
			},{
				name:'第三季度',
				value:90,
				color:'blue'
			},{
				name:'第四季度',
				value:305,
				color:'yellow'
			},]
			
			createSector(oPen,100,100,50,data);
			/**
			 * 
			 * @param {Object} open 笔的对象
			 * @param {Object} x 圆心坐标
			 * @param {Object} y 圆心坐标
			 * @param {Object} r 半径
			 * @param {Object} data 数据源
			 */
			function createSector(open,x,y,r,data){
				let sum=0;
				for(var i=0;i<data.length;i++){
					sum += data[i].value;
				}
				for(var i =0;i<data.length;i++){
					data[i].percentage = ((data[i].value*1.0)/sum)*360;
				}
				
				let startAngle = 0;
				for (var i=0;i<data.length;i++){
					oPen.beginPath()
					oPen.moveTo(x,y); 	
					oPen.arc(x,y,r,startAngle,startAngle+(Math.PI/180)*data[i].percentage,false);
					startAngle+=(Math.PI/180)*data[i].percentage;
					oPen.fillStyle=data[i].color;
					oPen.fill();
				}
			}
			
		}
	</script>
</html>
>>>>>>> dd0eb7ae3755996b1fe74c13037b7d351daeee27
